package com.Xht.www.servlet;

//后端响应修改房型信息请求

import com.Xht.www.dao.RoomTypeInfoDAO;
import com.Xht.www.po.RoomTypeInfoPO;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;

@WebServlet("/ModifyRoomServlet")
public class ModifyRoomServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        int roomTypeId = Integer.parseInt(request.getParameter("roomTypeId"));
        String merchantName = request.getParameter("merchantName");
        String bedType = request.getParameter("bedType");
        int remainingQuantity = Integer.parseInt(request.getParameter("remainingQuantity"));
        String keywords = request.getParameter("keywords");
        BigDecimal price = new BigDecimal(request.getParameter("price"));

        RoomTypeInfoPO roomTypeInfoPO = new RoomTypeInfoPO();
        roomTypeInfoPO.setRoomTypeId(roomTypeId);
        roomTypeInfoPO.setMerchantName(merchantName);
        roomTypeInfoPO.setBedType(bedType);
        roomTypeInfoPO.setRemainingQuantity(remainingQuantity);
        roomTypeInfoPO.setKeywords(keywords);
        roomTypeInfoPO.setPrice(price);

        RoomTypeInfoDAO roomTypeInfoDAO = new RoomTypeInfoDAO();
        try {
            roomTypeInfoDAO.updateRoomTypeInfo(roomTypeInfoPO);
            response.getWriter().println("房型信息修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            response.getWriter().println("房型信息修改失败");
        }
    }
}
